package com.management.controller;


import com.management.controller.form.SaveMenusForm;
import com.management.service.MenusService;
import com.management.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 龙世超
 * @since 2022-03-23
 */
@Api(tags = "菜单相关")
@RestController
@RequestMapping("/menus")
public class MenusController {
    @Resource
    private MenusService menusService;

    /**
     * 根据用户id获取其所有权限
     * @param accountId
     * @return
     */
    @ApiOperation("根据用户id获取其所有权限")
    @GetMapping("/getMenusByAccountId")
    public Result getMenusByAccountId(Integer accountId){
       Result result= menusService.findMenusByAccountId(accountId);
        return result;
    }

    /**
     * 根据角色ID获取所有菜单权限
     * @param roleNum 角色ID
     * @return
     */
    @ApiOperation("根据角色ID获取所有菜单权限")
    @GetMapping("getMenusByRoleNum")
    public Result getMenusByRoleNum(Integer roleNum){
        Result menusByRoleNum = menusService.getMenusByRoleNum(roleNum);
        return menusByRoleNum;
    }

    /**
     * 获取所有菜单
     * @return
     */
    @ApiOperation("获取所有菜单")
    @GetMapping("getAllMenus")
    public Result getAllMenus(){
        Result allMenus = menusService.getAllMenus();
        return allMenus;
    }

    /**
     * 修改角色菜单权限
     * @param saveMenusForm 参数
     * @return
     */
    @ApiOperation("修改角色菜单权限")
    @PostMapping("saveMenus")
    public Result saveMenus(@RequestBody SaveMenusForm saveMenusForm){
        Result result = menusService.saveMenus(saveMenusForm);
        return result;
    }
}

